#include "order/PowerStationPool.h"

DialPool::DialPool(QMap<ThreadPoint, NT::THREAD_STATE> &quote_thread,
                   QMap<QString, QMap<QString, QString>> &quote_rlmap,
                   QMap<QString, QString> &quote_strmap,
                   QMap<QString, bool> &quote_swtcmap,
                   QMap<QString, qint64> &quote_intmap,
                   QMap<QString, QList<QString>> &quote_ststrmap,
                   QMap<QString, QList<qint64>> &quote_stintmap,
                   QMap<QString, QList<QList<QString>>> &quote_stspcharmap,
                   QSqlDatabase *db){

    data_paste = new StickTData(quote_intmap);
    dial_object.insert(ThreadPoint::ANALY_STICK, data_paste);

    data_compare = new ExcelCompare(quote_ststrmap, quote_stspcharmap, false);
    dial_object.insert(ThreadPoint::ANALY_EXCELCOMPARE, data_compare);

    qRegisterMetaType<QMap<ThreadPoint, bool>>("QMap<ThreadPoint, bool>");

}


DialPool::DialPool(QMap<ThreadPoint, NT::THREAD_STATE> &quote_thread,
                   QMap<QString, QMap<QString, QString>> &quote_rlmap,
                   QMap<QString, QString> &quote_strmap,
                   QMap<QString, bool> &quote_swtcmap,
                   QMap<QString, qint64> &quote_intmap,
                   QMap<QString, QList<QString>> &quote_ststrmap,
                   QMap<QString, QList<qint64>> &quote_stintmap,
                   QMap<QString, NT::CUT_MEDIA_TYPE> &quote_mtpltype,
                   QSqlDatabase *db){

    mdrs_data_addtion = new MultidatasAddtion(quote_thread,
                                              quote_rlmap,
                                              quote_strmap,
                                              quote_ststrmap,
                                              db);
    dial_object.insert(ThreadPoint::MULTI_ADDTION, mdrs_data_addtion);

    mdrs_data_amend = new MultidatasAmend(quote_rlmap,
                                          quote_thread,
                                          quote_swtcmap,
                                          quote_strmap,
                                          quote_ststrmap,
                                          quote_mtpltype,
                                          db);

    dial_object.insert(ThreadPoint::MULTI_AMEND,
                       mdrs_data_amend);

    mdrs_head_crop = new MultidressMaker(quote_thread,
                                         quote_strmap,
                                         quote_stintmap,
                                         db);

    dial_object.insert(ThreadPoint::MULTI_CROP,
                       mdrs_head_crop);

    mdrs_data_del = new MultidatasTake(quote_thread,
                                       quote_stintmap,
                                       quote_ststrmap,
                                       quote_intmap,
                                       db);

    dial_object.insert(ThreadPoint::MULTI_REMOVE, mdrs_data_del);

    qRegisterMetaType<QMap<ThreadPoint, bool>>("QMap<ThreadPoint, bool>");

}

void DialPool::run(ThreadPoint obj){
    dial_object[obj]->setAutoDelete(false);
    if (dial_state[obj])
    {
        this->start(dial_object[obj]);
    } else {
        this->tryStart(dial_object[obj]);
    }
    dial_state[obj] = true;
}

DialPool::~DialPool(){
    QList<QRunnable *> i = dial_object.values();
    foreach(QRunnable *runner, i)
    {
        delete runner;
        dial_object.remove(dial_object.key(runner));
    }
}
